<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="100px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="物资名称" prop="wzmc" required >
						<el-input v-model="dataForm.wzmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="物资编号" prop="wzbh" required >
						<el-input v-model="dataForm.wzbh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="物资用途" prop="wzyt" required >
						<el-input v-model="dataForm.wzyt" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="物资型号" prop="wzxh" required >
						<el-input v-model="dataForm.wzxh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="负责部门" prop="fzbm" required >
						<el-select v-model="dataForm.fzbm" placeholder="请选择" clearable :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in fzbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="物资分类" prop="wzfl" required >
						<el-select v-model="dataForm.wzfl" placeholder="请选择" clearable :style='{"width":"100%"}' filterable >
							<el-option v-for="(item, index) in wzflOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="存放位置" prop="cfwz" required >
						<el-input v-model="dataForm.cfwz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="存储数量" prop="ccsl" required >
						<el-input v-model="dataForm.ccsl" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="生产日期" prop="scrq" required >
						<el-date-picker v-model="dataForm.scrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="datetime" format="yyyy-MM-dd HH:mm:ss" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="使用期限" prop="syqy" required >
						<el-input v-model="dataForm.syqy" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="生命周期" prop="smzq" required >
						<el-select v-model="dataForm.smzq" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in smzqOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="物资状态" prop="wzzt" required >
						<el-select v-model="dataForm.wzzt" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in wzztOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="投用日期" prop="tyrq" >
						<el-date-picker v-model="dataForm.tyrq" placeholder="请选择" clearable :style='{"width":"100%"}' type="date" format="yyyy-MM-dd" value-format="timestamp" >
						</el-date-picker>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="使用说明" prop="sysm" >
						<el-input v-model="dataForm.sysm" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					wzmc:undefined,
					wzbh:undefined,
					wzyt:undefined,
					wzxh:undefined,
					fzbm:undefined,
					wzfl:undefined,
					cfwz:undefined,
					ccsl:undefined,
					scrq:undefined,
					syqy:undefined,
					smzq:undefined,
					wzzt:undefined,
					tyrq:undefined,
					sysm:undefined,

        },
        rules: {
						wzmc:[
						{
							required:true,
							message:'请输入物资名称',
							trigger:'blur'
						},
						],
						wzbh:[
						{
							required:true,
							message:'请输入物资编号',
							trigger:'blur'
						},
						],
						wzyt:[
						{
							required:true,
							message:'请输入物资用途',
							trigger:'blur'
						},
						],
						wzxh:[
						{
							required:true,
							message:'请输入物资型号',
							trigger:'blur'
						},
						],
						fzbm:[
						{
							required:true,
							message:'请输入负责部门',
							trigger:'blur'
						},
						],
						wzfl:[
						{
							required:true,
							message:'请输入物资分类',
							trigger:'blur'
						},
						],
						cfwz:[
						{
							required:true,
							message:'请输入存放位置',
							trigger:'blur'
						},
						],
						ccsl:[
						{
							required:true,
							message:'请输入存储数量',
							trigger:'blur'
						},
						],
						scrq:[
						{
							required:true,
							message:'请输入生产日期',
							trigger:'blur'
						},
						],
						syqy:[
						{
							required:true,
							message:'请输入使用期限',
							trigger:'blur'
						},
						],
						smzq:[
						{
							required:true,
							message:'请输入生命周期',
							trigger:'blur'
						},
						],
						wzzt:[
						{
							required:true,
							message:'请输入物资状态',
							trigger:'blur'
						},
						],

        },
				fzbmOptions:[],
				wzflOptions:[{"fullName":"事故气体吸收装置","id":"1"},{"fullName":"通讯设施","id":"2"},{"fullName":"交通运输工具","id":"3"},{"fullName":"照明装置","id":"4"},{"fullName":"防护器材","id":"5"},{"fullName":"其他","id":"6"}],
				smzqOptions:[{"fullName":"已投用","id":"1"},{"fullName":"库存中","id":"2"},{"fullName":"报废","id":"3"}],
				wzztOptions:[{"fullName":"完好","id":"1"},{"fullName":"维修","id":"2"}],


      }
    },
    created() {
		this.getfzbmOptions();

    },
    methods: {
		getfzbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.fzbmOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/qyaqscYjwzgl/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {

        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/qyaqscYjwzgl',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/qyaqscYjwzgl/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>